package com.kh.pajx.sop.dao.bal.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.kh.pajx.sop.base.BaseDaoImpl;
import com.kh.pajx.sop.dao.bal.IBalTelfeeDriveDao;
import com.kh.pajx.sop.domain.bal.BalTelfeeDrive;

@Repository
@SuppressWarnings("unchecked")
public class BalTelfeeDriveDaoImpl extends BaseDaoImpl<BalTelfeeDrive> implements IBalTelfeeDriveDao {
	
	@Override
	public List<BalTelfeeDrive> findListByState(int state) throws Exception{
		return getSession().createQuery(//
				"FROM BalTelfeeDrive bal WHERE bal.billState=?") //
				.setParameter(0, state) //
				.list(); //
	}
	
	@Override
	public List<BalTelfeeDrive> findList(String billCode, int billState) throws Exception {
		return getSession().createQuery(//
				"FROM BalTelfeeDrive bal WHERE bal.billCode=? AND bal.billState=?") //
				.setParameter(0, billCode) //
				.setParameter(1, billState) //
				.list(); //
	}
	
	@Override
	public List<BalTelfeeDrive> findByBillCodeList(List<String> bumgrBills) throws Exception {
		return getSession().createQuery(//
				"FROM BalTelfeeDrive bal WHERE bal.billState=3 AND bal.billCode in (:billcodeList)") //
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
	
	@Override
	public List<BalTelfeeDrive> findByBillCodeList(List<String> bumgrBills, String areaCode) throws Exception {
		return getSession().createQuery(//
				"SELECT bal FROM BalTelfeeDrive bal,HsSchoolInfo scl WHERE bal.sclId = scl.sclId AND scl.areaCode=? AND bal.billState=3 AND bal.billCode in (:billcodeList)") //
				.setParameter(0, areaCode)//
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
	
	@Override
	public List<BalTelfeeDrive> findByBillCodeList(List<String> bumgrBills, String areaCode, String deptCode) throws Exception {
		// areaCode参数无用
		return getSession().createQuery(//
				"FROM BalTelfeeDrive bal WHERE bal.saleDeptId=? AND bal.billState=3 AND bal.billCode in (:billcodeList)") //
				.setParameter(0, deptCode) //
				.setParameterList("billcodeList", bumgrBills)//
				.list();
	}
}
